package cn.itcast.springboot.config;

import cn.itcast.springboot.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @package cn.itcast.springboot.pojo
 * @description: 配置拦截器
 * @author: 许超越
 * @date 2019/6/9 17:11
 * @version: V1.0
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    /**
     * 通过bean注解，将我们配置的拦截器注入spring容器
     * @return
     */
    @Bean
    public LoginInterceptor loginInterceptor() {
        return new LoginInterceptor();
    }

    /**
     * 从新定义接口中拦截器的方法
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //通过registry来注册拦截器，通过addPathPatterns添加拦截路径
        registry.addInterceptor(loginInterceptor()).addPathPatterns("/*");
    }
}
